let app = getApp()
var stylecss = require('../../utils/stylecss.js');
Component({
    properties: {
      scrollTop: {
        type: Number,
        observer: function(newVal, oldVal) {
          this.updatscroll()
        }
      },
      item: {
        type: Object,
        observer: function(newVal, oldVal) {
          this.updateRate()
        }
      }
      }, 
      data:{
        end_show:true,
        end:true
      },
    lifetimes: {
      ready: function() {
        let that = this;
        const query = wx.createSelectorQuery().in(this)
        setTimeout(() => { 
           query.select('#'+this.data.item.id).boundingClientRect(res=>{
                that.setData({
                  top:res.top
                })
              }).exec();
         }, 0);
       },
        attached: function () {
        
       }
      },
    methods: {
      updatscroll:function(){
        var nowtop=this.data.scrollTop-this.data.top
        var oldanima=this.data.oldanima
        if(nowtop<=0){
         this.setData({
           anima:oldanima
         })
        }else{
          this.setData({
              anima:''
          })
        }
     },
      jumpurl:function(e){
        var type=e.currentTarget.dataset.type
        if(type=='previewImage'){
           let imgurl=[];
           let imglist=this.data.list;
           let currentUrl =this.data.list[e.currentTarget.dataset.index].image
           for(var a=0;a<imglist.length; a++){
            imgurl.push(imglist[a].image);
           }
          wx.previewImage({
            current: currentUrl,
            urls:imgurl
          })  
        }else{
          this.data.item.list[e.currentTarget.dataset.index].link.title=this.data.item.list[e.currentTarget.dataset.index].title
          stylecss.jumpurl(this.data.item.list[e.currentTarget.dataset.index].link); 
        }
      },
      updateRate:function(){
        var list=this.data.item.list;
        var group_item=this.data.item.id+' .group_item';
        var item_image=this.data.item.id+' .item_image';
        var group_title=this.data.item.id+' .group_title';

        var css=stylecss.css(this.data.item.id);
        var anima=stylecss.animated(this.data.item.id);
        this.setData({
          oldanima:anima,
          anima:anima,
          css:css
        })
        var group_item_css=stylecss.css(group_item);
        var item_image_css=stylecss.css(item_image);
        var group_title_css=stylecss.css(group_title);
        this.setData({
          list:list,
          group_item_css:group_item_css,
          item_image_css:item_image_css,
          group_title_css:group_title_css
        })
      }
    }
});
